using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.UI.Base;
using Habanero.UI.Win;
using UseCaseGenerator.BO;

namespace UseCaseGenerator.UI
{
    /// <summary>
    /// A read-only grid control used for adding and editing Drops.
    /// </summary>
    public class DropsGridControl : UserControlWin, IFormControl
    {
        private readonly IControlFactory _controlFactory;

        public DropsGridControl(IControlFactory controlFactory)
        {
            _controlFactory = controlFactory;

            // Create the read-only grid
            IReadOnlyGridControl dropGridControl = _controlFactory.CreateReadOnlyGridControl();
            
            // Used to specify a custom UI def
            dropGridControl.Initialise(ClassDef.Get<Drop>(), "default");

            // Load the collection of Drops.  You can set the criteria and order by values here.
            BusinessObjectCollection<Drop> sampleCollection = Broker.GetBusinessObjectCollection<Drop>("", "");
            dropGridControl.SetBusinessObjectCollection(sampleCollection);

            // Set this to true to enable the filters, then add your filters below (see commented out line)
            dropGridControl.FilterControl.Visible = false;
            //dropGridControl.FilterControl.AddStringFilterTextBox("", "");

            // Uncomment this line to enable the default delete button
            //dropGridControl.Buttons.ShowDefaultDeleteButton = true;

            // Add the grid to the control so that it fills the control
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(dropGridControl, BorderLayoutManager.Position.Centre);
        }

        /// <summary>
        /// Called whenever the control is placed on a form by the menu system.  Put any initialisation
        /// code in here that must be run whenever the form is displayed.
        /// </summary>
        public void SetForm(IFormHabanero form) { }
    }
}